import 'package:flutter/material.dart';
import 'package:flutter_scaffold/tabbar/itemview.dart';
import 'package:flutter_scaffold/tabbar/selectedview.dart';

class TabbarPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      /// tabbar 控制器
      body: DefaultTabController(
        length: items.length,
        child: Scaffold(
          appBar: AppBar(
            title: Text("Tabbar choices"),
            bottom: TabBar(
                isScrollable: true,
                tabs: items.map((ItemView itemView) {
                  return Tab(text: itemView.title, icon: Icon(itemView.icon));
                }).toList()),
          ),
          body: TabBarView(
            children: items.map((ItemView item) {
              return Padding(
                padding: EdgeInsets.all(16.0),
                child: SelectedView(
                  item: item,
                ),
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}

const List<ItemView> items = [
  ItemView(title: "self drive", icon: Icons.directions_car),
  ItemView(title: "bicycle", icon: Icons.directions_bike),
  ItemView(title: "boat", icon: Icons.directions_boat),
  ItemView(title: "bus", icon: Icons.directions_bus),
  ItemView(title: "railway", icon: Icons.directions_railway),
  ItemView(title: "walk", icon: Icons.directions_walk),
];
